package com.maochang.dao.impl;


import com.maochang.bean.TAccount;
import com.maochang.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class AccountDaoImpl implements AccountDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 减钱
     * @param account
     * @return
     */
    @Override
    public boolean updateAccount1(TAccount account) {
        String sql="update t_account set money=money-? where name=?";
        int update = jdbcTemplate.update(sql, account.getMoney(), account.getName());
        return  update>0?true:false;
    }

    /**
     * 加钱
     * @param account
     * @return
     */
    @Override
    public boolean updateAccount2(TAccount account) {
        String sql="update t_account set money=money+? where name=?";
        int update = jdbcTemplate.update(sql, account.getMoney(), account.getName());
        return  update>0?true:false;
    }
}
